package com.team06.dao;

import com.team06.pojo.Cfce;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class CfceDao {
    private static final Logger LOGGER = LoggerFactory.getLogger(CfceDao.class);
    private final JdbcTemplate jdbcTemplate;

    public CfceDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void insertMessage(Cfce entity) {
        String sql = "INSERT INTO MSG_DFME_CFCE (" +
                "SENDER, RECEIVER, SEQUENCE, DTIME, MTYPE, STYPE, " +
                "DFLT_FLID, DFLT_FFID, DFLT_FIDE, DFLT_CFTP, DFLT_CFNO) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        try {
            jdbcTemplate.update(sql,
                    entity.getMetaSnDR(),
                    entity.getMetaRCVR(),
                    entity.getMetaSEQN(),
                    entity.getMetaDDTM(),
                    entity.getMetaTYPE(),
                    entity.getMetaSTYP(),
                    entity.getDfltFLID(),
                    entity.getDfltFFID(),
                    entity.getDfltFIDE(),
                    entity.getDfltCFTP(),
                    entity.getDfltCFNO()
            );
            LOGGER.info("Cfce 数据插入成功");
        } catch (Exception e) {
            LOGGER.error("Cfce 数据插入失败", e);
            throw new RuntimeException("Failed to insert Cfce message into database", e);
        }
    }
}
